<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="isSubmitted">
        <el-select v-model="queryParams.isSubmitted" placeholder="接收状态" clearable>
          <el-option
            v-for="item in receivedOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="examineUserName">
        <el-input
          v-model="queryParams.examineUserName"
          placeholder="请输入提交人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['examine:user:export']"
        >导出
        </el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="commonList">
      <el-table-column label="提交人" align="center" prop="userName" width="210px"/>
      <el-table-column label="所属部门" align="center" prop="ancestorNames" width="240px"/>
      <el-table-column label="提交状态" align="center" prop="isSubmitted">
        <template slot-scope="scope">
          {{ scope.row.isSubmitted > 0 ? '已提交' : '待提交' }}
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phonenumber"/>
      <el-table-column label="提交时间" align="center" prop="submitTime"/>
      <el-table-column label="提交详情" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleView(scope.row)"
            v-hasPermi="['examine:task:query']"
            v-if="scope.row.isSubmitted >0"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div style="margin: 2% auto auto 40%;">
      <el-button class="form_button_item" type="primary" @click="closeBtnHandler">返回</el-button>
    </div>
  </div>
</template>

<script>
import quarter from "@/views/tool/quarter";
import halfyear from "@/views/tool/halfyear";
import {listExamineUser, listMyExamine} from "@/api/examine/user/api";

export default {
  name: "Common",
  dicts: ['examine_user_submit_status'],
  components: {
    quarter,
    halfyear,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      cycleVal: '',
      // 通用考核表格数据
      commonList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examineId: undefined,
        isSubmitted: '',
        examineUserName: undefined,
        orderByColumn:'a.examine_id desc,a.is_submitted',
        isAsc:'desc'
      },
      receivedOptions: [
        {
          value: '',
          label: '全部'
        }, {
          value: 0,
          label: '待提交'
        }, {
          value: 1,
          label: '已提交'
        }
      ],
      examineYearOptions: {
        disabledDate: (time) => {
          const date = new Date()
          const year = date.getFullYear()
          const timeYear = time.getFullYear()
          return year > timeYear + 3
        }
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询通用考核列表 */
    getList() {
      this.loading = true;
      this.queryParams.examineId = this.$route.query.examineId;
      listExamineUser(this.queryParams).then(response => {
        this.commonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getCycleValue(data) {
      this.cycleVal = data;
    },
    getDictValue(data) {
      const obj = this.dict.type.examine_user_submit_status.find(d => Number(d.value) === data)
      if (obj) {
        return obj.label
      }
    },
    handleExport(){
      this.download('/examine/user/taskSubExport', {
        ...this.queryParams
      }, '提交人员数据导出.xlsx')
    },
    closeBtnHandler() {
      // 关闭当前页面
      this.$tab.closeOpenPage();
      // 刷新列表页面
      this.$tab.refreshPage({path: "/task/evaluateTable"});
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.cycleVal = '';
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push({path: "/task/add", query: {id: row.id}});
    },
    /**查看按钮操作 */
    handleView(row) {
      this.$router.push({path: "/task/submitTableView", query: {id: row.id}});
    },
    /**审核操作 */
    handleApprove(row) {
      this.$router.push({path: "/task/view", query: {id: row.id, view: false}});
    }
  }
};
</script>
